<template>
  <div>
    <Header></Header>
    <div class="bg mt-4" :style="bgStyle"></div>
    <section class="book-info-section">
      <div class="book-detail">
          <img :src="data.imgurl?data.imgurl:'/static/img/'+ data.id +'.png'" class="book-cover img-book fl">
          <div>
            <h3 class="col-auto">{{data.name}}</h3>
            <a class="book-meta">{{data.author}} ></a>
          </div>
      </div>
      <div class="book-reader top mt-1">
          <p class="reader-item"><span class="title">点击数</span><span class="content">{{data.count || '--' }}</span></p>
          <p class="reader-item"><span class="title">读者留存率</span><span class="content">{{data.retention|| '' }}%</span></p>
          <p class="reader-item"><span class="title">日更新字数/天</span><span class="content">{{data.dailyupdate || '--' }}</span></p>
      </div>
      <div class="book-intro part">
          <p class="long-intro">{{data.content}}</p>
      </div>
      <div class="book-menu">
          <div class="menu-title fl">目录</div>
          <p class="menu-content fr gray">{{data.update_time}}</p>
      </div>
      <div class="chapter-detail">
          <a class="a-detail" v-for="(item, index) in Chapter" :key="index" @click="jumpTo(item.url)">
              <dt>{{ item.name }}</dt>
              <dd>{{ item.update_time }}</dd>
          </a>
      </div>
      <div v-if="Chapter.length == 0" class="center">暂未收录</div>
    </section>
  </div>
</template>

<script>
import Header from './components/Header.vue'

export default {
  components: {
    Header
  },
  data() {
    return {
      data: this.$route.query,
      Chapter: []
    }
  },
  mounted() {
    this.$http.post('api/list', {
      pagesize: 10,
      pagenum: 1,
      id: this.data.id
    }, {emulateJSON: true}).then((response) => {
      this.Chapter = response.data.data.list
    })
  },
  computed: {
    bgStyle() {
      return {
        backgroundImage: `url(${this.data.imgurl ? this.data.imgurl : '/static/img/' + this.data.id + '.png'})`,
        opacity: 0.5,
        filter: 'blur(1px)',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center top'
      }
    }
  },
  methods: {
    jumpTo(target) {
      this.$router.push({path: '/ebook', query: {url: target}})
    },
    setbg(url) {
      return {background: url}
    }
  }
}
</script>

<style lang='scss' scoped>
  .bg {
    width: 100%;
    height: 12rem;
  }
  .book-info-section {
    margin-top: -10rem !important;
    background-color: white;
    p{
      margin:0;
    }
  }
  .book-detail {
      // justify-content: space-between;
      overflow: hidden;
      padding: 0 0.6rem;//
      display: flex;
      z-index: 99;
  }

  .center {
      text-align: center;
  }
  .book-cover {
      display: inline-block;
      width: 6rem;
      height: 8rem;
      margin-right: 0.5rem;
      background-color: transparent;
  }

  .fl {
      float: left;
  }

  .book-detail .book-desc {
      position: relative;
  }

  .book-detail .book-desc .book-title {
      color: #333;
      // line-height: 1;
      margin: 0.2rem 0 0.3px;
      font-weight: 500;
      font-size:1rem;
  }

  .book-detail .book-desc .book-meta {
      font-size: 0.8rem;
      line-height: 1rem;
      align-items: flex-end;
      white-space: normal;
  }

  .book-reader {
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      text-align: center;
      padding: 0.6rem 0;
      border-top: 1px solid #ebebeb;
  }

  .book-reader .reader-item {
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
  }

  .book-reader .reader-item span.title {
      font-size: 12px;
      color: #999;
  }

  .book-reader .reader-item span {
      display: block;
      line-height: 1.5;
  }

  .book-intro.part {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 4;
      -webkit-box-orient: vertical;
  }

  .book-intro {
      position: relative;
      padding: 0.4rem 0.9rem 0;
      font-size: 0.7rem;
      line-height: 1.5;
      text-align: justify;
      border-top: 1px solid #ebebeb;
  }

  .book-menu {
      position: relative;
      margin-top: 0.4rem;
      padding: 0 0.4rem;
      border-top: 1px solid #ebebeb;
      border-bottom: 1px solid #ebebeb;
      box-sizing: border-box;
      overflow: hidden;
  }

  .book-menu a {
      display: block;
  }

  .book-menu .menu-title {
      font-size: 0.8rem;
      line-height: 1.8rem;
      font-weight: 400;
      color:#333;
  }

  .book-menu .menu-content {
      position: relative;
      font-size: 0.8rem;
      line-height: 1.8rem;
      width: 70%;
      text-align: right;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      padding-right: 1rem;
  }

  .gray {
      color: #969ba3;
  }
  .fr {
      float: right;
  }
  .split-dot {
      padding: 0 1px;
  }

  .chapter-detail {
      position: relative;
      border-top: 1px solid #ebebeb;
      border-bottom: 1px solid #ebebeb;
      box-sizing: border-box;
      overflow: hidden;
      padding: 0 1.4rem;
  }

  .a-detail {
      display: flex;
      justify-content: space-between;
      line-height: 1.5rem;
      height: 1.5rem;
  }
</style>
